/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package	dao;

import Hibernate.HibernateUtil;

import pojo.Book;
import pojo.Thongso;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class ThongsoDAO extends AbstractDAO {

	@Override
	protected Class getPOJOClass() {
		// TODO Auto-generated method stub
		return Thongso.class;
	}
	
    public Thongso getThongsoByID(int id){
    	Thongso ts = null;
    	List<Thongso> l=this.getList();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try{
            ts = (Thongso)session.get(Thongso.class, id);
        }
        catch(HibernateException ex){
            System.out.print(ex);
        }
        finally{
            session.close();
        }
        return ts;
    }

	public  boolean capnhatThongSo(String soBookTrenTrang,
			String soBookMacDinh, String kieuSapxep) {
		// TODO Auto-generated method stub
		boolean flag= false;
		Session session = HibernateUtil.getSessionFactory().openSession();
		ThongsoDAO dao= new ThongsoDAO();
		Thongso ts= (Thongso) dao.getList().get(0);
		ts.setSoBookTrenTrang(Short.parseShort(soBookTrenTrang));
		ts.setSoBookMacDinh(Short.parseShort(soBookMacDinh));
		ts.setKieuSapXep(Short.parseShort(kieuSapxep));
		

		Transaction transaction = null;
		try {
			transaction = session.beginTransaction();
			session.saveOrUpdate(ts);
			transaction.commit();
			flag= true;
		} catch (Exception e) {
			transaction.rollback();
		}
		finally{
		session.close();
		}		
		
		
		
		return flag;
	}
   
   
}
